package com.example.ndktest;

import android.util.Log;

import androidx.annotation.Keep;

import org.greenrobot.eventbus.EventBus;

import java.util.Random;
import java.util.UUID;

public class JNIHelper {

    // 导入动态库
    static {
        System.loadLibrary("jni-tools");
    }

    private static JNIHelper instance;
    String s = "shadow";
    static int count = 3;

    private JNIHelper(){}

    static JNIHelper getInstance() {
        if (instance == null) {
            instance = new JNIHelper();
        }
        return instance;
    }

    public native String accessField();
    public native void accessStaticField();
    public native String accessStaticMethod();
    public native int accessMethod();

    @Keep
    private void updateStatus(String msg){
        if (msg.toLowerCase().contains("error")) {
            Log.e("JniHelper", "Native Error:" + msg);
        } else {
            Log.i("JniHelper", "Native Msg:" + msg);
        }
    }

    public static native String getStringFromNative();

    // 本地排序方法
    public static native boolean doSort(int[] array);

    public void callback(int[] array){
        EventBus.getDefault().post(array);
    }

    public static String getUUID(){
        return UUID.randomUUID().toString();
    }

    public int genRandomInt(int max) {
        return new Random().nextInt(max);
    }
}
